package servlet;

import java.io.IOException;
import java.sql.Date;
import java.util.Collection;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import junit.framework.Assert;
import fulbitofacil.exception.DAOExcepcion;
import fulbitofacil.modelo.ReservaCancha;
import fulbitofacil.negocio.ReservaNegocio;

/**
 * Servlet implementation class ReservaServlet
 */
@WebServlet("/ReservaServlet")
public class ReservaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ReservaServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		ReservaNegocio R = new ReservaNegocio();
		try{
			 String distrito=request.getParameter("txtDistrito");
			 System.out.println(request.getParameter("txtFechaIni"));
			 System.out.println(request.getParameter("txtFechaFin"));
			 Date fecIni = Date.valueOf(request.getParameter("txtFechaIni"));
			 Date fecFin = Date.valueOf(request.getParameter("txtFechaFin"));
			 int horIni = Integer.valueOf(request.getParameter("txtHoraIni"));
			 int horFin = Integer.valueOf(request.getParameter("txtHoraFin"));
			 
			 
			 Collection<ReservaCancha> Lista = R.ListarCancha(distrito, fecIni, fecFin, horIni, horFin);
								
	     	if (Lista.size()>0)
	     	{
	     		System.out.println("Bingo");
				request.setAttribute("Canchas", Lista);
			    }
		    else
			{ System.out.println("No se ha encontrado naranjas"); 
			};
		} 
		catch (DAOExcepcion e) 
		{
		   Assert.fail("Fallo: " + e.getMessage());
		}
	
		RequestDispatcher rd = request.getRequestDispatcher("Alquiler.jsp");
		rd.forward(request, response);
		
		
	}

}
